﻿
 
		using System;
		using System.ServiceModel;
		using System.ServiceModel.Channels;
		using System.ServiceModel.Dispatcher;
				using System;
		using System.ServiceModel;
		using System.ServiceModel.Channels;
		using System.ServiceModel.Dispatcher;
				using System;
		using System.ServiceModel;
		using System.ServiceModel.Channels;
		using System.ServiceModel.Dispatcher;
		namespace Enter.Your.Namespace.Here { 
					internal partial class AuthorizationContext
			{
				private const string CONTEXT_ID = "__AUTHORIZATIONCONTEXT__";
															
        public static AuthorizationContext Active {
            get { return getOrCreateWCFStored(); }
        }

        private static AuthorizationContext getOrCreateWCFStored()
        {
            var wcfContext = OperationContext.Current;
            if (wcfContext == null)
                throw new NotSupportedException(
                    "OperationContext must not be null with WCF stored context: AuthorizationContext");
            AuthorizationContextExtension extension = wcfContext.Extensions.Find<AuthorizationContextExtension>();
            if(extension == null)
                throw new NotSupportedException("OperationContext must have AuthorizationContextExtension added");
            return extension.Current;
        }


		
        internal class AuthorizationContextExtensionInitialization : IInstanceContextInitializer
        {
            public void Initialize(InstanceContext instanceContext, Message message)
            {
                AuthorizationContextExtension extension = new AuthorizationContextExtension();
                instanceContext.Extensions.Add(extension);
            }
        }

        internal class AuthorizationContextExtension : IExtension<InstanceContext>
        {
            public readonly AuthorizationContext Current = new AuthorizationContext();

            public void Attach(InstanceContext owner)
            {
            }

            public void Detach(InstanceContext owner)
            {
            }
        }
									public System.Security.Principal.GenericPrincipal UserRoles { get; set; }
						public static System.Security.Principal.GenericPrincipal CurrentPrincipal {
				get {
					return Active.UserRoles;
				}
			}
							}

		 } namespace Enter.Your.OtherOrSame.Namespace.Here { 
					internal partial class AuthenticationContext
			{
				private const string CONTEXT_ID = "__AUTHENTICATIONCONTEXT__";
															
        public static AuthenticationContext Active {
            get { return getOrCreateWCFStored(); }
        }

        private static AuthenticationContext getOrCreateWCFStored()
        {
            var wcfContext = OperationContext.Current;
            if (wcfContext == null)
                throw new NotSupportedException(
                    "OperationContext must not be null with WCF stored context: AuthenticationContext");
            AuthenticationContextExtension extension = wcfContext.Extensions.Find<AuthenticationContextExtension>();
            if(extension == null)
                throw new NotSupportedException("OperationContext must have AuthenticationContextExtension added");
            return extension.Current;
        }


		
        internal class AuthenticationContextExtensionInitialization : IInstanceContextInitializer
        {
            public void Initialize(InstanceContext instanceContext, Message message)
            {
                AuthenticationContextExtension extension = new AuthenticationContextExtension();
                instanceContext.Extensions.Add(extension);
            }
        }

        internal class AuthenticationContextExtension : IExtension<InstanceContext>
        {
            public readonly AuthenticationContext Current = new AuthenticationContext();

            public void Attach(InstanceContext owner)
            {
            }

            public void Detach(InstanceContext owner)
            {
            }
        }
									public System.Security.Principal.GenericIdentity UserIdentity { get; set; }
						public static System.Security.Principal.GenericIdentity CurrentIdentity {
				get {
					return Active.UserIdentity;
				}
			}
							}

		 } namespace Enter.Your.Whichever.Namespace.Here { 
					internal partial class ObjectContext
			{
				private const string CONTEXT_ID = "__OBJECTCONTEXT__";
															
        public static ObjectContext Active {
            get { return getOrCreateWCFStored(); }
        }

        private static ObjectContext getOrCreateWCFStored()
        {
            var wcfContext = OperationContext.Current;
            if (wcfContext == null)
                throw new NotSupportedException(
                    "OperationContext must not be null with WCF stored context: ObjectContext");
            ObjectContextExtension extension = wcfContext.Extensions.Find<ObjectContextExtension>();
            if(extension == null)
                throw new NotSupportedException("OperationContext must have ObjectContextExtension added");
            return extension.Current;
        }


		
        internal class ObjectContextExtensionInitialization : IInstanceContextInitializer
        {
            public void Initialize(InstanceContext instanceContext, Message message)
            {
                ObjectContextExtension extension = new ObjectContextExtension();
                instanceContext.Extensions.Add(extension);
            }
        }

        internal class ObjectContextExtension : IExtension<InstanceContext>
        {
            public readonly ObjectContext Current = new ObjectContext();

            public void Attach(InstanceContext owner)
            {
            }

            public void Detach(InstanceContext owner)
            {
            }
        }
									public object Instance { get; set; }
						public static object Current {
				get {
					return Active.Instance;
				}
			}
							}

		 } 